$(function(){
	//删除
	$('.delete-list').on('click',function(){
		popup(this,"{:url('delete')}");
		
	});
	//启用
	$('.startusing').on('click',function(){
		popup(this,"{:url('state')}");
		
	});
	//禁用
	$('.forbidden').on('click',function(){
		popup(this,"{:url('state')}");
		
	});
	//全选
	$('.check-all').on('click',function(){
		checkall(this)
	});
	$('.check-list').on('click',function(){
		checkall(this)
	});
	//删除多个
	$(".delete-multiple").on('click',function(){
		popup(this,"{:url('delete')}");
	})
	$('.choose').on('click', function() {
		var index = parent.layer.getFrameIndex(window.name); 
		parent.$('.car_type').val($(this).closest('tr').find('.type_name').html());
		parent.$('.car_type_id').val($(this).data('id'));
		console.log($('.cancel_cost').html())
		if(($(this).closest('tr').find('.chartered_charge').html()-0)>0){
			parent.$('input[name="pre_fee"]').val($(this).closest('tr').find('.chartered_charge').html()-0)
			parent.$('.estimated_time').val($(this).closest('tr').find('.chartered_hour').html()-0)
			parent.$('.distance').val($(this).closest('tr').find('.chartered_km').html()-0)
		}
		if(parent.$('.car_type').data('type')=='order'){
			if(parent.$('select[name="order_type"]').val()){
				console.log(11)
				if(parent.$('.car_type_id').val()){
					console.log(22)
					if(parent.$('.distance').val()){
						console.log(33)
						cost({car_type_id:parent.$('.car_type_id').val(),estimate_mileage:parent.$('.distance').val(),order_type:parent.$('select[name="order_type"]').val(),},parent.$('input[name="pre_fee"]'),index)
					}else{
						parent.layer.close(index);
					}
				}else{
					parent.layer.close(index);
				}
			}else{
				parent.layer.close(index);
			}
			
		}else{
		parent.layer.close(index);
		}
	});
	function cost(data,obj,obj2){
		Load()
		$.ajax({
			type:'post',
			url:'{:url("/adminapi/Order/getOrderPreFee")}',
			data:data,
			success:function(res){
				Load(1)
				if(res.code==1){
					console.log(res)
					obj.val(res.data.estimate_cost.toFixed(2))
					parent.layer.close(obj2);
				}else{
					Err(res.msg)
				}
			},
			error:function(){
				Err('预算失败')
			}
		})
	}
})
